import {exce, exceWithLogCallback} from "./cmd"

/**
 * mvn clean install
 *
 * @param {*} args  { mavenHome:string, settingsPath:string, pomPath:string }
 * @param {*} logCallback (data:any) => void
 * @returns
 */
const install = (args, logCallback) => {
  const cmd = `${args.mavenHome}/bin/mvn clean install -s ${args.settingsPath} -f ${args.pomPath}`
  return exceWithLogCallback(cmd, logCallback)
}



/**
 * mvn deploy:deploy-file
 * @param {*} args
 */
const deployFile = (args) => {
  let cmd = `${args.mavenHome}/bin/mvn deploy:deploy-file `
  cmd += `--settings ${args.settingsPath} `
  cmd += `-DgroupId=${args.groupId} `
  cmd += `-DartifactId=${args.artifactId} `
  cmd += `-Dversion=${args.version} `
  cmd += `-Dpacking=${args.packing} `
  cmd += `-DrepositoryId=${args.repositoryId} `
  cmd += `-Durl=${args.repositoryUrl} `
  if (args.packing === 'pom') {
    cmd += `-Dfile=${args.pomPath} `
  } else {
    cmd += `-Dfile=${args.jarPath} -DpomFile=${args.pomPath}`
  }
  return exce(cmd)
}

export { install, deployFile }
